package com.tuling.controller;

import com.tuling.common.Result;
import com.tuling.pojo.Question;
import com.tuling.service.QuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(tags = "问题查询")
@RestController
public class QuestionController {

    @Resource
    private QuestionService questionService;

    static List<String> types = new ArrayList<>();

    static {
        // KafKa,MQ,,Redis,,ZK,分库分表,并发专题,微服务,计算机基础

        types.add("JVM");
        types.add("MySQL");
        types.add("Spring");
    }

    /**
     * 获取问题，保证12小时内获取到的只有一个问题
     *
     * @return
     */
    @ApiOperation(value = "找指定类型问题", notes = "找指定类型问题")
    @GetMapping("/question")
    public Result<Question> question() {
        int l = (int) (System.currentTimeMillis() % types.size());
        return questionService.question(types.get(l));
    }

    @GetMapping("/clearCache")
    public void clearCache() {
        questionService.clearCache();
    }
}
